#include <iostream>
#include <unordered_set>
using namespace std;
struct Node{
	int value;
	Node* next=nullptr;
	Node(int __value=0):value(__value){}
};
void showList(Node*);
Node* createList(int[],int);
Node* removeDuplicates(Node*);
int main(){
	int n[5]={1,1,2,3,3};
	Node* l=createList(n,5);
	removeDuplicates(l);
	showList(l);
	return 0;
}
Node* removeDuplicates(Node* head) {
    if (!head) return nullptr;
    unordered_set<int> seen;
    Node* current = head;
    Node* prev = nullptr;
    while (current) {
        if (seen.find(current->value) != seen.end()) {
            prev->next = current->next;
            delete current;
            current = prev->next;
        } else {
            seen.insert(current->value);
            prev = current;
            current = current->next;
        }
    }
    return head;
}
void showList(Node* head){
	Node* p=head;
	while(p->next!=nullptr){
		cout<<p->value<<' ';
		p=p->next;
	}
	cout<<p->value<<endl;
}
Node* createList(int values[],int size){
	Node* p=new Node(values[0]);
	Node* head=p;
	for(int i=1;i<size;++i){
		p->next=new Node(values[i]);
		p=p->next;
	}
	return head;
}
